/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BusinessLogic;


import DataAccess.*;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;

/**
 *
 * @author thangvv0907i
 */
public class Login_BL {

    public User checkLogin(String txtUserName, String txtPassword) {
        int permission = new Login_DA(txtUserName, txtPassword).checkLogin();
        User userObj = null;
        if (permission != 0) {
            Object[][] objStd = new Login_DA(txtUserName, txtPassword).Select_DA();
            String[] userFeild = new String[13];
            
            int a;

            for (int j = 0; j < objStd.length; j++) {
                for (int i = 0; i < objStd[j].length; i++) {
                    if (objStd[j][i] == null) {
                        break;
                    }
                    userFeild[i] = (String) objStd[j][i];
                    userObj = new User(userFeild[0], userFeild[3], userFeild[4], userFeild[2],userFeild[5],userFeild[6],userFeild[7], userFeild[8], userFeild[11],permission);
                }
            }
        }
        return userObj;
    }
    public void setLastLogin_BL(String UID,String dateFormat){
        
        Calendar cal = Calendar.getInstance();
        SimpleDateFormat sd = new SimpleDateFormat(dateFormat);
        String dateNow = (String)sd.format(cal.getTime());
        System.out.println(""+dateNow);
        new Logout_DA().setLastLogin_DA(UID,dateNow);
    }
}
